package com.atguigu.szdz.dcsyl.service.impl;

import com.atguigu.szdz.dcsyl.service.YlycService;
import com.atguigu.szdz.dcsyl.utils.MapperUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("ylycService")
public class YlycServiceImpl implements YlycService {
    @Autowired
    private MapperUtils mapperUtils;

    @Override
    public void updateDate(String table_code, List<Map<String, String>> list) {
        mapperUtils.updataBySql("delete from dc_ylyc");
        String sql = "";
        for (Map<String, String> map : list) {
            System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaa:" + table_code + ",bbbbbbbbbbbbb:" + map);
            String well_name = map.get("well_name");
            String depth = map.get("depth");
            String lithology = map.get("lithology");
            String sound_waves = map.get("sound_waves");
            String density = map.get("density");
            String well_road = map.get("well_road");
            String natural_gamma = map.get("natural_gamma");
            String natural_potential = map.get("natural_potential");
            String deep_resistivity = map.get("deep_resistivity");
            sql = sql + "('" + well_name + "','" + depth + "','" + lithology + "','" + sound_waves + "','" + density + "','" + well_road
                    + "','" + natural_gamma + "','" + natural_potential + "','" + deep_resistivity + "','" + table_code + "'),";
        }
        sql = "insert into dc_ylyc (well_name,depth,lithology,sound_waves,density,well_road" +
                ",natural_gamma,natural_potential,deep_resistivity,table_code) values " + sql;
        sql = sql.replaceFirst(",$", "");
        System.out.println("sssssssssssssss:" + sql);
        mapperUtils.updataBySql(sql);
    }

    @Override
    public List<Map<String, Object>> getYlycList(Integer currentPage, String keyword) {
        String sql = "select * from dc_ylyc" + keyword + " limit 10 offset " + (currentPage - 1) * 10;
        return mapperUtils.queryBySql(sql);
    }

    @Override
    public List<Map<String, Object>> getCount(String s) {
        return mapperUtils.queryBySql(s);
    }

    @Override
    public List<Map<String, Object>> getYlycList() {
        return mapperUtils.queryBySql("select * from dc_pmjl");
    }
}
